#[derive(FromForm)]
struct WsFormTask {
    skip_number: usize
}

#[derive(Serialize)]
struct WsCopywriteTask {
    id: usize,
    topic_id: String,
    bt_file: String,
    requirement: String
}

#[derive(Serialize)]
struct WsClipTask {
    id: usize,
	topic_id: String,
    bt_file: String
}

#[derive(Serialize)]
struct WsExamineListTask {
    copywrite: Vec<WsCopywriteTask>,
    clip: Vec<WsClipTask>
}

#[post("/ws_lib/task_list", data="<form>")]
fn ws_task_list(form: Form<WsFormTask>, cookies: Cookies, state: State<MySqlDriver>) -> Json<Value> {
    let user_info: UserInfo = get_cookies(&cookies);
    let mut task_list: Vec<WsExamineListTask> = Vec::new();
    let pool_result: Result<Pool, mysql::Error> = Pool::new(state.driver.as_str());
    let pool: Pool;
    if let Ok(p) = pool_result {
        pool = p;
    } else {
        return Json(to_value(task_list).unwrap());
    }
    let conn_result: Result<PooledConn, mysql::Error> = pool.get_conn();
    let mut conn: PooledConn;
    if let Ok(c) = conn_result {
        conn = c;
    } else {
        return Json(to_value(task_list).unwrap());
    }

    let mut sql: String = format!("SELECT `co`.`id`, `t`.`movie_name` AS `topic_id`, `t`.`bt_file`, `co`.`requirement` FROM `copywrite_order` AS `co` INNER JOIN `topic` AS `t` ON `t`.`id` = `co`.`topic_id` WHERE `co`.`status` = 1 AND `co`.`get_user_id` = {} ORDER BY `co`.`id` ASC LIMIT {}, 10", user_info.id, form.skip_number);
    let rows: Vec<Row> = conn.query(sql).unwrap();
    let mut copywrite_list: Vec<WsCopywriteTask> = Vec::new();
    for row in rows {
		let (id, topic_id, bt_file, requirement): (usize, String, String, String) = from_row(row);
        let bt_file_hostr: HoString = HoString::copy_string(bt_file);
        let bt_file_array: Vec<HoString> = bt_file_hostr.split_str("|");
        let mut bt_file_first: String = String::new();
        if let Some(first) = bt_file_array.get(0) {
            bt_file_first = first.to_string();
        }
		copywrite_list.push(WsCopywriteTask {
			id: id,
			topic_id: topic_id,
            bt_file: bt_file_first,
            requirement: requirement
        });
    }
    sql = format!("SELECT `clip_o`.`id`, `t`.`movie_name` AS `topic_id`, `t`.`bt_file` FROM `clip_order` AS `clip_o` INNER JOIN `topic` AS `t` ON `t`.`id` = `clip_o`.`topic_id` WHERE `clip_o`.`status` = 1 AND `clip_o`.`get_user_id` = {} ORDER BY `clip_o`.`id` ASC LIMIT {}, 10", user_info.id, form.skip_number);
    let rows: Vec<Row> = conn.query(sql).unwrap();
    let mut clip_list: Vec<WsClipTask> = Vec::new();
    for row in rows {
		let (id, topic_id, bt_file): (usize, String, String) = from_row(row);
        let bt_file_hostr: HoString = HoString::copy_string(bt_file);
        let bt_file_array: Vec<HoString> = bt_file_hostr.split_str("|");
        let mut bt_file_first: String = String::new();
        if let Some(first) = bt_file_array.get(0) {
            bt_file_first = first.to_string();
        }
		clip_list.push(WsClipTask {
			id: id,
			topic_id: topic_id,
            bt_file: bt_file_first
        });
    }
    task_list.push(WsExamineListTask {
        copywrite: copywrite_list,
        clip: clip_list
    });
    return Json(to_value(task_list).unwrap());
}

